
import React from 'react';
import css from './index.less';
import PropTypes from 'prop-types';

export default class Input extends React.Component {
  constructor(props) {
    super(props);
  }

  static propTypes = {
    label: PropTypes.string,
    inputValue: PropTypes.number,
    left: PropTypes.number,
  };

  static defaultProps = {
    label: '二级标题',
    inputValue: 0,
    left: 'px',
  };

  onChange = (e) => {
    const { onChange = () => {} } = this.props;
    if (e.target) {
      onChange(parseFloat(e.target.value));
    } else if (e) {
      onChange(parseFloat(e));
    }

  };

  render() {
    const { label, inputValue, left } = this.props;
    const props = {
      className: css.wrapper,
      style: {
        position: 'absolute',
        left: left,
        top: 0,
      }
    };
    return (
      <div {...props}>
        <span className={css.label}>{label}</span>
        <input className={css.show} onChange={this.onChange.bind(this)} value={inputValue} type="number"/>
      </div>
    );
  }
}
